import {
  queryIndicators,
  queryWaterQualityIndicators,
  queryWaterQualityIndicatorsByYear,
  queryQualityIndicatorsAnalysis,
  queryExceedingStandardAnalysis,
} from '../services/index';

export default {
    namespace: 'quality',
  
    state: {
      IndicatorsResource: {},
      WaterQualityIndicatorsResource: [
        { time: '20190810', value: 0.9, standval: 1.2 },
        { time: '20190811', value: 2.2, standval: 1.4 },
        { time: '20190812', value: 1.5, standval: 1.6 },
        { time: '20190813', value: 3.2, standval: 1.5 },
        { time: '20190814', value: 1.0, standval: 1.5 },
      ],
      WaterQualityIndicatorsByYearResource: [
        { time: '2019-01', total: 12, minv: 5, maxv: 12 },
        { time: '2019-02', total: 22, minv: 4, maxv: 62 },
        { time: '2019-03', total: 15, minv: 6, maxv: 82 },
        { time: '2019-04', total: 32, minv: 5, maxv: 58 },
        { time: '2019-05', total: 10, minv: 5, maxv: 62 },
        { time: '2019-06', total: 8, minv: 4, maxv: 32 },
        { time: '2019-07', total: 22, minv: 3, maxv: 82 },
        { time: '2019-08', total: 17, minv: 8, maxv: 72 },
        { time: '2019-09', total: 20, minv: 8, maxv: 52 },
        { time: '2019-10', total: 9, minv: 10, maxv: 42 },
        { time: '2019-11', total: 42, minv: 15, maxv: 32 }
      ],
      QualityIndicatorsAnalysisResource: [
        { time: '2019-01', value: 12, radio: 65 },
        { time: '2019-02', value: 22, radio: 10 },
        { time: '2019-03', value: 15, radio: 15 },
        { time: '2019-04', value: 32, radio: 95 },
        { time: '2019-05', value: 10, radio: 85 },
        { time: '2019-06', value: 8, radio: 45 },
        { time: '2019-07', value: 22, radio: 50 },
        { time: '2019-08', value: 17, radio: 32 },
        { time: '2019-09', value: 20, radio: 25 },
        { time: '2019-10', value: 9, radio: 51 },
        { time: '2019-11', value: 42, radio: 15 }
      ],
      ExceedingStandardAnalysisResource: [
        { "title": "耗氧量", "value": 2 },
        { "title": "二氧化氮", "value": 2 },
        { "title": "氢化物", "value": 2 },
        { "title": "总大肠杆菌", "value": 2 },
      ],
    },
  
    effects: {
      // 指标值
      *queryIndicators({ payload }, { call, put }) {
        const data = yield call(queryIndicators, payload)
        const { success, message, status, ...other } = data
        if (success) {
          console.log(other.fieldAliases)
          const result = Array.isArray(other.features) && other.features.length>0 ? other.features[0].attributes : {}
          yield put({
            type: 'setState',
            payload: {
              IndicatorsResource: result,
            },
          })
        } else {
          throw data
        }
      },
      // 水质指标监测情况
      *queryWaterQualityIndicators({ payload }, { call, put }) {
        const data = yield call(queryWaterQualityIndicators, payload)
        const { success, message, status, ...other } = data
        if (success) {
          yield put({
            type: 'setState',
            payload: {
              WaterQualityIndicatorsResource: other.data,
            },
          })
        } else {
          throw data
        }
      },
      *queryWaterQualityIndicatorsByYear({ payload }, { call, put }) {
        const data = yield call(queryWaterQualityIndicatorsByYear, payload)
        const { success, message, status, ...other } = data
        if (success) {
          yield put({
            type: 'setState',
            payload: {
              WaterQualityIndicatorsByYearResource: other.data,
            },
          })
        } else {
          throw data
        }
      },
      *queryQualityIndicatorsAnalysis({ payload }, { call, put }) {
        const data = yield call(queryQualityIndicatorsAnalysis, payload)
        const { success, message, status, ...other } = data
        if (success) {
          yield put({
            type: 'setState',
            payload: {
              QualityIndicatorsAnalysisResource: other.data,
            },
          })
        } else {
          throw data
        }
      },
      *queryExceedingStandardAnalysis({ payload }, { call, put }) {
        const data = yield call(queryExceedingStandardAnalysis, payload)
        const { success, message, status, ...other } = data
        if (success) {
          yield put({
            type: 'setState',
            payload: {
              ExceedingStandardAnalysisResource: other.data,
            },
          })
        } else {
          throw data
        }
      },
    },
  
    reducers: {
      setState(state, action) {
        return {
            ...state,
            ...action.payload
        };
      }
    },
  }
  